﻿<form id="mainform" name='frm' method=post action="">
   	<div id="toolbar-button">
			<div class="item" onclick="add()" id="itemButton1" title="Thêm mới">
				<div id="addnew-global-button"></div>
			</div>
			<div class="item" onclick="del()" id="itemButton0" title="Xóa">
				<div id="delete-global-button"></div>
			</div>			
	</div>
    <table style="margin-top: 10px" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr class="alternate-row">
                <th width="2%" style="text-align: center" nowrap="nowrap">STT</th>
                <th width="2%" style="text-align: center; vertical-align: middle" nowrap valign="center">
                    <input type=checkbox name=DELALL onclick="SelectAllU(this,'DEL')">
                </th>
                <th width="20%" style="text-align: left">Tên loại sản phẩm</th>
        		<th width="20%" style="text-align: left">Số loại sản phẩm con</th>
                <th width="5%" style="text-align: center" style="text-align: left">Kích hoạt</th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
            <?php
if (count($this->data) == 0) {
	echo "<tr><td colspan=6>Không có dữ liệu được tìm thấy</td></tr>";
} else {
	$stt = 1;
}
foreach ($this->data as $item) {
			   ?>
            <tr>
                <td style="text-align: center" ><?=$stt ?></td>
                <td style="text-align: center; vertical-align: middle">
                    <input id="<?=$item['DEALCATEGORYID'] ?>" type="checkbox" name="DEL[]" value="<?=$item['DEALCATEGORYID'] ?>" />
                </td>
                <td> 
                <a href="#" onClick="ItemClickU(<?php echo $item['DEALCATEGORYID'] ?>)">
                        <?=$item['NAME']; ?></a>
                </td>
				<td> 
                <a href="#" onClick="ItemClickU(<?php echo $item['DEALCATEGORYID'] ?>)">
                        <?=$item['SUBCOUNT']; ?></a>
                </td>
                <td style="text-align: center" onClick="ItemClickU(<?php echo $item['DEALCATEGORYID'] ?>)"><span id="status<?=$item['DEALCATEGORYID'] ?>">
                        
                        <?php if ($item['STATUS'] != 1) {
		echo '<font color="#004FA0"> Chưa kích hoạt</font>';
	} else {
		echo 'Đã kích hoạt';
	} 	?></a>
                    </span>
                </td>
            </tr>
			
            <?php $stt++;
					}
				 ?>
        </tbody>
    </table>

</form>
<script>
    function ItemClickU(id)
    {
        document.frm.action = "/globalconfig/dealcategory/input/id/"+id;
        document.frm.submit();
    }
	
    function add(){
        document.location.href='/globalconfig/dealcategory/input';
    }
	
    function SelectAllU(selobj,childobj){
         var arr = document.getElementsByName(childobj+"[]");
         for(var i=0;i<arr.length;i++){
            arr[i].checked = selobj.checked;
         }
    }
	
    function del()
    {
    	  var ln = 0;
          var arr = document.getElementsByName('DEL[]');
          for(var i = 0 ; i < arr.length ;i++ )
          {
                  if(arr[i].checked == true)
                  {
                          ln = 1;
                          break;
                  }
          }
          
          if(ln == 1)
          {
                  if(confirm("<?php echo "Bạn có muốn xóa không?"; ?>")){	
                          document.frm.action="/globalconfig/dealcategory/delete";
                          document.frm.method="post";
                          document.frm.submit();
                  }
          }
          else
          {
                  alert("Bạn phải chọn một dòng để xóa");
          }
    }

</script>
